//
//  TicketViewCell.m
//  Shengzhuli
//
//  Created by FXGuo on 2018/1/19.
//  Copyright © 2018年 kamangkeji. All rights reserved.
//

#import "TicketViewCell.h"
#import <UIImageView+WebCache.h>

@interface TicketViewCell()

@property (weak, nonatomic) IBOutlet UIImageView *logoImg;
@property (weak, nonatomic) IBOutlet UILabel *nameLab;
@property (weak, nonatomic) IBOutlet UILabel *statusLab;
@property (weak, nonatomic) IBOutlet UILabel *timeLab;

@end

@implementation TicketViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setModel:(TicketModel *)model
{
    _model = model;
    [self.logoImg sd_setImageWithURL:[NSURL URLWithString:model.ticketLogo] placeholderImage:GetImage(@"person_avatar")];
    self.nameLab.text = model.name;
    self.timeLab.text = [NSString stringWithFormat:@"优惠券使用期限：%@止",[self spToDateString:model.validateTime]];
    if ([model.status isEqualToString:@"0"]) {//未使用
        self.statusLab.text = @"未使用";
        self.statusLab.backgroundColor = RGBColor(106, 203, 154);
    }else if ([model.status isEqualToString:@"1"]) {//已使用
        self.statusLab.text = @"已使用";
        self.statusLab.backgroundColor = RGBColor(253, 152, 64);
    }else {
        self.statusLab.text = @"已过期";
        self.statusLab.backgroundColor = RGBColor(238, 238, 244);
    }
}

- (NSString *)spToDateString:(NSString *)sp
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    formatter.dateFormat = @"YYYY年MM月dd日";
    
    NSDate *timeDate = [NSDate dateWithTimeIntervalSince1970:[sp floatValue]/1000];
    return [formatter stringFromDate:timeDate];
}

@end
